export const required = (message) => ({
  message,
  required: true,
  type: "require",
});
export const min = (message, length = 3) => ({
  message,
  min: length,
  type: "min",
});
export const max = (message, length = 15) => ({
  message,
  max: length,
  type: "max",
});

export const noSpace = (message) => ({
  type: "noSpace",
  message,
});

export const pattern = (message, reg) => ({
  // 组合正则
  message,
  pattern: reg,
  type: "pattern",
});

const isEmailOrIsPhone = /^[1][3,4,5,6,7,8,9][0-9]{9}$|\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/; // 邮箱或手机号
const userNamePattern = /^[a-zA-Z0-9_·\-\u4e00-\u9fa5]+$/; // 中英文，数字和_·-等符号

export const inputUsernamePattern = pattern(
  `用户名仅支持中英文，数字和_·-等符号`,
  userNamePattern
);
export const inputNoSpace = noSpace(`不可以包含空格哟`);
export const inputEmailOrPhone = pattern(
  "这好像不是邮箱或手机号",
  isEmailOrIsPhone
);
